<?php

namespace app\logic\model\music;

use app\logic\model\LogicModel;
use app\logic\single\MusicSingle;

class MusicSelectedPackDetailLogicModel extends LogicModel
{
    protected $name='music_selected_pack_detail';

    function music(){
        return $this->hasOne(MusicLogicModel::class,'id','music_id');
    }
    public function getByPackId($id,$field='*')
    {
        $list = $this->where('pack_id',$id)->field($field)->select()->toArray();
        if(!empty($list)){
            foreach ($list as &$val){
                [$val['music'],$val['writer']] = MusicSingle::getInstance()->getMusicAndUser($val['music_id']);
            }
            unset($val);
        }
        return $list;
    }
}